<%@page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="x" uri="/soar-bx-tags"%>
<x:HeaderParts modal="true"/>
<x:MainPartsTag modal="true">
<x:zone name="MainZone">
<x:Form action="auth/approle.shtml">
<x:ParamsParts>
<x:TextField name="id" type="hidden"/>
</x:ParamsParts>
<x:DataViewParts>
<x:PanelHeading>
<%-- 应用角色-
<s:iterator value="approles" id="ars" status="st">
${ars.ROLE_NAME }
<s:if test="!#st.last">,</s:if>
</s:iterator> --%>
<div class="dropdown">
  <button class="btn btn-info btn-sm" type="button" id="dropdown1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">复制权限</button>
  <div class="dropdown-menu" aria-labelledby="dropdown" style="max-height: 200px;overflow-y:scroll;">
  	<s:iterator id="sys" value="sysPageList">
  		<s:if test="#sys.ID != id">
		<label class="checkbox" style="display: inline-block;margin-left: 25px;">
	  		<input type="checkbox" name="rids" value="${sys.ID }" >${sys.ROLE_NAME }
	  	</label>
	  	</s:if>
	</s:iterator>
	<x:Button role="info" value="确定" onclick="chhoseRole()"></x:Button>
  </div>
</div>
</x:PanelHeading>
<x:PanelBody>
<x:Table checkBoxName="ids" rootNodeValue="000000000000000000" keyFieldName="ID" parentFieldName="PID" tree="true" showLevel="4" showIndex="false" list="appmenu">
	<x:Column value="MU_NAME" label="名称" isTreeCol="true" style="width:30%;" escape="false"><input type="hidden" value="{CT}" data-id="{ID}" name="cts"></x:Column>
	<x:Column label="图标" style="width:50px;" escape="false" align="center">
	<i class="{MU_ICON} fa-2x"></i>
	</x:Column>
	<x:Column value="MU_URL" label="链接" style="width:60%;" maxLength="100" title="{MU_URL}"></x:Column>
	<x:Column label="终端" checks="1:PC,2:移动" style="width:5%" align="center" iif="true">
	<x:If test="MU_PLATFORM==1"><i class="fa fa-windows fa-2x"></i></x:If>
	<x:If test="MU_PLATFORM==2"><i class="fa fa-mobile fa-2x"></i></x:If>
	</x:Column>
</x:Table>
</x:PanelBody>
<x:PanelFooter>
<x:ButtonsParts>
<!-- <input type="button" value="复制" class="btn btn-info" onclick="X.Modal('auth/approle!chooseRole.shtml','','','80%','80%','选取角色')"> -->
<x:Button role="success" value="保存" onclick="doSave()"></x:Button>
<x:Button role="default" value="关闭" onclick="X.CloseLayer()"></x:Button>
</x:ButtonsParts>
</x:PanelFooter>
</x:DataViewParts>
<x:JsParts fn="chooseRole,doSave">
function doSave()
{
	var fg=true;
	$("input[name='ids']").each(function(){
		if(this.checked)
		{
			if($("input[name='ids'][data-id='"+$(this).attr("data-pid")+"']:first").length > 0)
			{
				if(!$("input[name='ids'][data-id='"+$(this).attr("data-pid")+"']:first").get(0).checked)
				{
					fg=false;
				}
			}
		}
	});
	if(fg)
	{
		X.Submit('saveRoleMenu',1,true);
	}
	else
	{
		X.Alert("父级菜单未勾选！");
	}
}
function chhoseRole()
{
	var ids="";
	$("input[name='rids']").each(function(){
		if(this.checked)
		{
			ids+=this.value+',';
		}
	});
	if(ids.length == 0)
	{
		X.Alert("未选取任何角色！");
	}
	else
	{
		$.ajax({
			url:'<so:Context/>/auth/approle!getRoles.shtml',
			data:{"id":ids},
			async:false,
			dataType:"text",
			success:function(data)
			{
				var ars=data.split(",");
				console.log(ars);
				for(var i=0;i < ars.length;i++)
				{
					if(ars[i]!="")
					{
						$("input[name='ids'][data-id='"+ars[i]+"']").attr("checked","checked");
					}
				}
			}
		});
	}
}

$("input[name='cts']").each(function(){
	if(this.value!="0" && this.value!="null")
	{
		$("input[name='ids'][data-id='"+$(this).attr("data-id")+"']").attr("checked","checked");
	}
});
</x:JsParts>
</x:Form>
</x:zone>
</x:MainPartsTag>
